﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace printdesign
{
    /// <summary>
    /// WindowTestprint.xaml 的交互逻辑
    /// </summary>
    public partial class WindowTestprint : Window
    {
        public WindowTestprint()
        {
            InitializeComponent();
        }

        private void LoadClick(object sender, RoutedEventArgs e)
        {
            using (FileStream fs = new FileStream(
          System.IO.Path.Combine(Environment.CurrentDirectory, "saved.xaml"),//path为路径
          FileMode.Open, FileAccess.Read))
            {
                Canvas newCanvas = (Canvas)XamlReader.Load(fs);
                // showxamlgrid.Children.Add(newCanvas);
                fs.Close();
            }
        }
        Student student = new Student() { name="fff",age="11111"};
        PrintDialog p = new PrintDialog();
        private void printClick(object sender, RoutedEventArgs e)
        {
           
            using (FileStream fs = new FileStream(
         System.IO.Path.Combine(Environment.CurrentDirectory, "saved.xaml"),//path为路径
         FileMode.Open, FileAccess.Read))
            {
                Canvas newCanvas = (Canvas)XamlReader.Load(fs);
                foreach(var a in newCanvas.Children)
                {
                    if(a is Label)
                    {
                        Label l = (Label)a;
                        string s = l.Tag.ToString();
                        l.Content = App.GetObjectPropertyValue<Student>(student, s);
                    }
                }
                p.ShowDialog();
                p.PrintVisual(newCanvas, "111");
                // showxamlgrid.Children.Add(newCanvas);
                fs.Close();
            }
        }
    }
}
